﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Mtool.FSM
{
    public class PictInputVariable
    {
        private string name;
        private List<string> values;
        private int order;

        public PictInputVariable(string name, string value)
        {
            this.name = name;
            this.values.Add(value);
            this.order = 1;
        }

        public PictInputVariable(string name, List<string> values, int order)
        {
            this.name = name;
            this.values = values;
            this.order = order;
        }

        public List<string> Values
        {
            get { return values; }
        }

        public string ValuesString
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                int ithS = 0;
                foreach (string s in Values)
                {
                    if (ithS++ > 0)
                        sb.Append(",");
                    sb.Append(s);
                }
                return sb.ToString();
            }
            set
            {
                if(value == null)
                {
                    values.Clear();
                    return;
                }
                string[] segs = value.Split(new string[]{","}, StringSplitOptions.RemoveEmptyEntries);
                values = new List<string>(segs);
            }
        }

        public int Order
        {
            get { return order; }
            set { order = value; }
        }

        public string Name
        {
            get { return name; }
        }
    }

    public class PictOutputVarList
    {
        public PictOutputVarList()
        {
            Variables = new List<PictOutputVariable>();
        }

        public List<PictOutputVariable> Variables
        {
            get;
            private set;
        }

        public PictOutputVariable this[string key]
        {
            get 
            {
                foreach (PictOutputVariable v in Variables)
                {
                    if (v.Name == key)
                        return v;
                }
                return null;
            }
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            foreach (PictOutputVariable pov in Variables)
            {
                sb.AppendFormat("{0}:{1} , ", pov.Name, pov.Value);
            }            
            return sb.ToString();
        }
    }

    public class PictOutputVariable
    {
        private string _name;
        private string _value;

        public PictOutputVariable(string name, string value)
        {
            _name = name;
            _value = value;
        }

        public string Name
        { get { return _name; } }

        public string Value
        {
            get { return _value; }
        }
    }    
}
